package com.example.demo.util;

import com.example.demo.mapper.DeviceMapper;
import com.example.demo.pojo.BaseBean;
import com.example.demo.pojo.RestResponse;
import com.example.demo.pojo.zuwang.zuwang.Device;
import com.example.demo.udp.DemoUdpNettyServerHandler;
import org.apache.poi.ss.formula.functions.T;

public class DeviceNoConnect {

    public static RestResponse<T> noConnectZuwang(DeviceMapper deviceMapper, String target){
        Device device = deviceMapper.selectByTarget(target);
        if (device == null){
            return RestResponse.validfail("无此设备");
        }
        if (device.getState().equals("0")){
            return RestResponse.validfail("此设备已断开");
        }
        BaseBean baseBean = DemoUdpNettyServerHandler.senderMap.get(target);
        if (baseBean == null){
            return RestResponse.validfail(  target +"连接没有建立，请稍后再试");
        }
        return RestResponse.success();
    }

    public static RestResponse<T> noConnect(DeviceMapper deviceMapper, String target){
        Device device = deviceMapper.selectByTarget(target);
        if (device == null){
            return RestResponse.validfail("无此设备");
        }
        if (device.getState().equals("0")){
            return RestResponse.validfail("此设备已断开");
        }
        if (device.getState().equals("3")){
            return RestResponse.validfail("此设备未组网");
        }
        BaseBean baseBean = DemoUdpNettyServerHandler.senderMap.get(target);
        if (baseBean == null){
            return RestResponse.validfail(  target +"连接没有建立，请稍后再试");
        }
        return RestResponse.success();
    }
}
